Skip to content

Conversation

srogmann
Copy link
Contributor

@srogmann srogmann commented Oct 10, 2025

Close #16136

This PR handles LaTeX blocks in (...) and [...], as well as dollar amounts like $100 that should not be interpreted as inline LaTeX.

Examples (e.g. prompt "Think of a grade 4 math question regarding amounts."):

  • ( \mathrm{GL}_2(\mathbb{F}_7) ): Group of invertible matrices with entries in (\mathbb{F}_7).
  • Some kernel of (\mathrm{SL}_2(\mathbb{F}_7)):
    [
    \left{ \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}, \begin{pmatrix} -1 & 0 \ 0 & -1 \end{pmatrix} \right} = {\pm I}
    ]
  • $100 and $12.99 are amounts, not LaTeX.
  • I have $10, $3.99 and $x + y$ and $100x$. The amount is $2,000.

@allozaur : I wrote most of this PR a week ago, only just now noticed issue #16136 and your PR #16496. In math-formulas.ts, I've added examples for Storybook, along with tests for Vitest. Feel free to take a look and let me know your thoughts. Detecting inline LaTeX is inherently tricky, so my approach likely won't cover every edge case, but I hope it's a step in the right direction.

@allozaur
Copy link
Collaborator

allozaur commented Oct 11, 2025

Hey @srogmann! Thank you for this contribution :) Yeah, we will definitely work sth out from these PRs :)

@allozaur
Copy link
Collaborator

allozaur commented Oct 15, 2025

@ggerganov could u also please take a look at this and test your edge cases?

@watamario15 @squik67 also some feedback & testing from you would be really useful :)

@ggerganov
Copy link
Member

These are still not rendered (using gpt-oss):

image

@allozaur
Copy link
Collaborator

Okay, thanks for reporting @ggerganov. I'd like to wait just a bit longer for @watamario15 and @squik67 to add their feedback and verify if there are more edge cases to be addressed before we introduce any further improvements to this.

@srogmann
Copy link
Contributor Author

srogmann commented Oct 15, 2025

Thanks for the tests! I can reproduce the non-rendered formulas. The \[-marker is not at line-begin in the non-working cases.

Example: working and non-working.

- Algebra:
\[
x = \frac{-b \pm \sqrt{\,b^{2}-4ac\,}}{2a}
\]
- Algebra: \[
x = \frac{-b \pm \sqrt{\,b^{2}-4ac\,}}{2a}
\]

I'll have a look at it.

@watamario15
Copy link

From my quick check, this doesn't get rendered:

- 1 kg の質量は  
  \[
  E = (1\ \text{kg}) \times (3.0 \times 10^8\ \text{m/s})^2 \approx 9.0 \times 10^{16}\ \text{J}
  \]  
  というエネルギーに相当します。これは約 21 百万トンの TNT が爆発したときのエネルギーに匹敵します。

@watamario15
Copy link

It's working well on my end with these ↑ commits. Thanks!

(I found a small issue where GPT-OSS tends to escape *s in expressions, resulting them being rendered as \*. Not that important, just fyi.)

@watamario15
Copy link

Oh, it looks like erroring on

\[
\boxed{
\begin{aligned}
N_{\text{att}}^{\text{(MHA)}} &=
h \bigl[\, d_{\text{model}}\;d_{k} + d_{\text{model}}\;d_{v}\, \bigr]   && (\text{Q,K,V の重み})\\
&\quad+ h(d_{k}+d_{k}+d_{v})                                          && (\text{バイアス Q,K,V)}\\[4pt]
&\quad+ (h d_{v})\, d_{\text{model}}                                 && (\text{出力射影 }W^{O})\\
&\quad+ d_{\text{model}}                                            && (\text{バイアス }b^{O})
\end{aligned}}
\]

@srogmann
Copy link
Contributor Author

@watamario15 Thanks! The rendering is now better, but the spacers (e.g. [4pt]) still cause display issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: mathematical expression not decoded in llama.cpp web interface

4 participants